/*******************************************************************
 * 外语翻译平台(translate) 
 *
 * 成都一亿信息技术公司 版权所有
 * 
 * Copyright (C) 2010 Transer Information Technology Co., Ltd.
 *
 * @Version : 1.0  2011-1-12 下午12:02:55
 *
 * LogDaoImpl.java
 *
 *******************************************************************/
package com.transer.persistance.dao.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.transer.persistance.bean.LoginLog;
import com.transer.persistance.dao.ILogDao;
import com.transer.persistance.exception.TranserDatabaseException;

/**
 * class defination are there
 * 
 * @author Mark
 * 
 * @version 1.0 ywengineer@gmail.com
 * 
 */
public class LogDaoImpl extends SqlMapClientDaoSupport implements ILogDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.transer.persistance.dao.ILogDao#addLoginLog(com.transer.persistance
	 * .bean.LoginLog)
	 */
	@Override
	public void addLoginLog(LoginLog log) throws TranserDatabaseException {
		try {
			getSqlMapClientTemplate().insert("LoginLog.addLog", log);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw new TranserDatabaseException("addLoginLog error", e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.transer.persistance.dao.ILogDao#getLoginLogs(int)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<LoginLog> getLoginLogs(int userID) throws TranserDatabaseException {
		try {
			return getSqlMapClientTemplate().queryForList("LoginLog.getUserLogs", userID);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw new TranserDatabaseException("getLoginLogs error :" + userID, e);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.transer.persistance.dao.ILogDao#getLastLogin(int)
	 */
	@Override
	public LoginLog getLastLogin(int userID) throws TranserDatabaseException {
		try {
			return (LoginLog) getSqlMapClientTemplate().queryForObject("LoginLog.getLastLog", userID);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw new TranserDatabaseException("getLastLogin error :" + userID, e);
		}
	}
}
